// pages/yuanx/yuanx.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    leftCircle: -135,
    rightCircle: -135,

  },

  //倒计时
  countDown: function (sumM,ysM) {
    var that = this;
    //大概两秒加完（实际多一点）
    var time = 300;
    //已收占总金额的半分比
    var bfb = (ysM / sumM).toFixed(2);
    console.log(bfb)
    // //转一圈所需要添加
    var sum = 360;
    //每次增加
    var add = sum / (time/2);
    //右边添加
    var rightAdd = bfb > 0.5 ? 45 : this.data.rightCircle + sum * bfb;
    console.log(rightAdd)
    //左边添加
    var leftAdd = bfb > 0.5 ? this.data.leftCircle + (sum * (bfb-0.5)) : this.data.leftCircle;
    console.log(this.data.leftCircle + (sum * (bfb - 0.5)))
   
    
    var interval = setInterval(function () {
      time--;
     
      if (that.data.rightCircle < rightAdd) {
        that.data.rightCircle = that.data.rightCircle + add
        if (that.data.rightCircle > rightAdd){
          that.data.rightCircle = rightAdd
        }
       
      } else if (that.data.leftCircle < leftAdd) {
        
        that.data.leftCircle = that.data.leftCircle + add
        if (that.data.leftCircle > leftAdd) {
          that.data.leftCircle = leftAdd
        }
      }
     
      that.setData({
        rightCircle: that.data.rightCircle,
        leftCircle: that.data.leftCircle
      })
      if (that.data.rightCircle == rightAdd && that.data.leftCircle == leftAdd) {
        clearInterval(interval);
      }
    }, 10)
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.countDown(40000,15000);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})